package br.com.DoceMagia.modelo.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConexaoBanco {

	private Connection connection;
	private String url = "jdbc:mysql://localhost/agendadocemagia";
	private String user = "root";
	private String pass = "123";

	public Connection getConnection() throws SQLException {

		try {

			Class.forName("com.mysql.jdbc.Driver");

			connection = DriverManager.getConnection(url, user, pass);

		} catch (ClassNotFoundException ex) {
			System.out.println("Problemas driver de conexao com o banco de dados." + ex);

		}
		return connection;
	}
	
	public void closeStatement (Statement statement){
		if(statement == null){
			return;
		}
			try {
				statement.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	public void closeResultSet (ResultSet resultSet){
		if(resultSet == null){
			return;
		}
			try {
				resultSet.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	public void closeConnection(Connection conn){
		if(conn == null){
			return;
		}
			try {
				conn.close();
			} catch (SQLException e) {
			}
	}
	
	public void closeAll(Connection conn, Statement statement){
		closeStatement(statement);
		closeConnection(conn);
	}
}